# -*- coding: utf-8 -*-
"""
Created on Tue Jun  5 21:16:41 2018

@author: Administrator
"""

from agilepipe.spine import AgilePipe

#%%t
#he code below is to coregister PD to CBF

modality = '_PD'   #the image modality in the original_dirpath   '_T1' '_BOLD' '_CBF'  '_PET'
manipulate_methods = { 'Spm_coregister_SC':{}
                      }
#dirpath 也是一个dict，其keys与manipulate_methods完全相同，但元素是对应处理方法所生成的文件夹的名字。
dirpath_dict = {'original_dirpath':[],
                     #用来存放其实的文件。
                     'Spm_coregister_SC':[]
                    }

#agile_pipe()用ccs处理BOLD的测试代码
original_dirpath = r'/media/root/Elements4/XuanWu_last/CBF_processing/PD'
#the first element of dirpath_list is very important which is used as reference image when coregister CBF to T1
dirpath_list = [r'/media/root/Elements4/XuanWu_last/CBF_processing/CBF_clear_background','',''] #即使没有用也要赋值，否则会报错
dirpath_dict = dirpath_dict
manipulate_methods = manipulate_methods
parallel_core = 0.7
AgilePipe(modality,original_dirpath,dirpath_list,dirpath_dict,manipulate_methods,parallel_core)


#%%
#the code below is used to process the T1 image
modality = '_T1'   #the image modality in the original_dirpath   '_T1' '_BOLD' '_CBF'  '_PET'
manipulate_methods = { 'Spm_coregister_SC':{},
                      'Spm_segment_SS':{}
                      }
#dirpath 也是一个dict，其keys与manipulate_methods完全相同，但元素是对应处理方法所生成的文件夹的名字。
dirpath_dict = {'original_dirpath':[],
                     #用来存放其实的文件。
                     'Spm_coregister_SC':[],
                     'Spm_segment_SS':[]
                    }

#agile_pipe()用ccs处理BOLD的测试代码
original_dirpath = r'/media/root/Elements4/XuanWu_last/CBF_processing/T1'
#the first element of dirpath_list is very important which is used as reference image when coregister CBF to T1
dirpath_list = [r'/media/root/Elements4/XuanWu_last/CBF_processing/PD_SC','',''] #即使没有用也要赋值，否则会报错
dirpath_dict = dirpath_dict
manipulate_methods = manipulate_methods
parallel_core = 0.7
AgilePipe(modality,original_dirpath,dirpath_list,dirpath_dict,manipulate_methods,parallel_core)


#%%
#the code below is used to process the CBF image
modality = '_CBF'     #'_T1' '_BOLD' '_CBF'  '_PET'
manipulate_methods = { 'Spm_normalize_SN':{},
                      'Spm_reslice_SR':{},
                      'Spm_smooth_SSM':{'fwhm':['6']}
                      }
#dirpath 也是一个dict，其keys与manipulate_methods完全相同，但元素是对应处理方法所生成的文件夹的名字。
dirpath_dict = {'original_dirpath':[],
                     #用来存放其实的文件。
                     'Spm_normalize_SN':[],
                     'Spm_reslice_SR':[],
                     'Spm_smooth_SSM':[]
                    }

#agile_pipe()用ccs处理BOLD的测试代码
original_dirpath = r'/media/root/Elements4/XuanWu_last/CBF_processing/CBF_clear_background'
#the first element of dirpath_list is very important which is used as deformation field 
#the second element of dirpath_list can be used in the reslice processing as the "Image Defining Space" filepath
dirpath_list = [r'/media/root/Elements4/XuanWu_last/CBF_processing/T1_SC_SS','/root/Documents/BrainMask_05_61x73x61.nii',''] #即使没有用也要赋值，否则会报错
dirpath_dict = dirpath_dict
manipulate_methods = manipulate_methods
parallel_core = 0.7
AgilePipe(modality,original_dirpath,dirpath_list,dirpath_dict,manipulate_methods,parallel_core)


#%%
#make mask before Z_standardize

from agilepipe.process import  Create_groupmask

source_dirpath = r'/media/root/Elements4/XuanWu_last/CBF_processing/CBF_clear_background_SN_SR_del-subj24'
mnimask_filepath = r'/root/Documents/BrainMask_05_61x73x61.nii'
great_groupmask = Create_groupmask([source_dirpath,mnimask_filepath])



#%%
#perform Z_standardiz

from agilepipe.process import Z_standardize #,Mean_division

previous_dirpath = r'/media/root/Elements4/XuanWu_last/CBF_processing/CBF_clear_background_SN_SR_del-subj24'
mask_filepath = r'/media/root/Elements4/XuanWu_last/mask/GM_mask/T1_SC_SS_GM_SN_SR_mean_threshold-0.5/T1_SC_SS_GM_SN_SR_mean_threshold-0.5.nii'
present_dirpath = r'/media/root/Elements4/XuanWu_last/CBF_processing/CBF_clear_background_SN_SR_del-subj24_z'

Z_standardize([previous_dirpath,mask_filepath,present_dirpath])

##%% mean division
#
#previous_dirpath = r'/media/root/Elements4/standardize_test/CBF_clear_background_SN_SR_SSM-6'
#mask_filepath = r'/media/root/Elements4/XuanWu_z_sm666_pearson_0620/CBF_processing/make_mask_before_z_standardize/sws_CBF_26_intersect_mask.nii'
#present_dirpath = r'/media/root/Elements4/standardize_test/CBF_clear_background_SN_SR_SSM-6_md'
#
#Mean_division([previous_dirpath,mask_filepath,present_dirpath])


#%%